package com.hanbang.maige.pressenter.home;

import com.hanbang.maige.code.base.presenter.BasePresenter;
import com.hanbang.maige.mode.HttpRequest;
import com.hanbang.maige.mode.httpresponse.BaseHttpResponse;
import com.hanbang.maige.mode.httpresponse.HomeResponse;
import com.hanbang.maige.utils.http.httpquest.HttpCallBack;
import com.hanbang.maige.utils.http.httpquest.HttpRequestParam;
import com.hanbang.maige.view.home.IHomeBaseView;

/**
 * 作者　　: 李坤
 * 创建时间:2016/9/19　17:05
 * 邮箱　　：496546144@qq.com
 * <p>
 * 功能介绍：
 */

public class HomePresenter extends BasePresenter<IHomeBaseView.IHomeView> {

    /**
     * 作者　　: 李坤
     * 创建时间: 2016/10/26 14:33
     * <p>
     * 方法功能：首页	ShouYe
     * guanggao：广告
     * News:新闻
     * huodong:活动
     */

    public void getHttpData() {
        HttpCallBack.Buider buider = new HttpCallBack.Buider(this);
        buider.setShowLoadding(false);
        buider.setSwipeRefreshLayout(mvpView.getSwipeRefreshLayout());
        buider.setLoadingAndRetryManager(mvpView.getLoadingAndRetryManager());
        HttpCallBack<HomeResponse> callBack = new HttpCallBack<HomeResponse>(buider) {
            @Override
            public void onSuccess(HomeResponse result) {
                super.onSuccess(result);

                if (result.isSucceed()) {
                    result.json = null;
                    mvpView.updataUI(result);
                }

            }
        };

        HttpRequestParam param = new HttpRequestParam("ShouYe");
        mvpView.addSubscription(HttpRequest.executeGet(callBack, param));
    }

    /**
     * 作者　　: 李坤
     * 创建时间: 2016/10/26 14:33
     * <p>
     * 方法功能：活动报名	huodongBaoming	ActivityID：活动ID
     */

    public void postBaoming(String ActivityID, final int position) {
        HttpCallBack.Buider buider = new HttpCallBack.Buider(this);
        buider.setHint("正在为您报名");
        HttpCallBack<BaseHttpResponse> callBack = new HttpCallBack<BaseHttpResponse>(buider) {
            @Override
            public void onSuccess(BaseHttpResponse result) {
                super.onSuccess(result);
                if (result.isSucceed()) {
                    mvpView.baomingSuccess(result.getMsg(), position);
                } else {
                    mvpView.showErrorSnackbar(result.getMsg());
                }

            }
        };

        HttpRequestParam param = new HttpRequestParam("huodongBaoming");
        param.addParam("ActivityID", ActivityID);
        mvpView.addSubscription(HttpRequest.executeGet(callBack, param));
    }
}
